import matplotlib.pyplot as plt
import numpy as np
import os

def ACT():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    ind = np.arange(len(x_data))
    y_data1 = [84.6410650739137, 69.13073139337203, 69.78768624747677, 63.781388135075886, 68.9693010542348, 68.98263314111372, 68.39552402092615, 60.367004949340654, 67.90329408617384, 63.975736254051306, 70.01137383314843, 70.03862559981681]
    y_data2 = [86.09349074664965, 69.8080808080808, 70.22224993764031, 64.32270114942528, 69.3751269035533, 69.43862770012707, 68.86123680241327, 60.888712661908535, 68.33249560191003, 64.53935521347663, 71.62879276952873, 71.62879276952873]
    w = 0.2
    ax = plt.subplot(111)
    a = ax.bar(ind,y_data1,width=0.2,align='center',color='red')
    b = ax.bar(ind+w,y_data2,width=0.2,align='center', color='lightseagreen')
    ax.set_xticks(ind+w)
    ax.set_xticklabels( ('MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF') )
    plt.legend((a,b),('ave ACT','worst ACT'))
    plt.autoscale(tight=True)
    plt.title('The average/worst ACT')
    plt.tight_layout()
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    ACT()